package org.moyrax.nereyda.services.core
{
	import com.adobe.serialization.json.JSON;
	
	public dynamic class Response
	{
		// Expresiones regulares para el
		// parseo de código en JSON.
		//
		private var objExp  :RegExp = /(?:\{.*\}+)/;
		
		public function Response( data:String = null )
		{
			if ( data )
				this.parse( data );
		}

		public function parse( data:String ):void
		{
			var dataArr :Array = objExp.exec( data );
			
			if ( !data || !dataArr )
				return;
			
			if ( dataArr.length > 0 )
				data = dataArr[0];

			var object:Object = JSON.decode( data );
			
			if ( object == null )
				return;
			
			for ( var item:String in object ) {
				this[item] = object[item];
			}
		}
	}
}